// https://www.luogu.com.cn/problem/P5716

#include <stdio.h>

int main() {
    int y, m;
    scanf("%d%d", &y, &m);
    int ans[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
    if (y % 400 == 0 || (y % 4 == 0 && y % 100 != 0)) {
        ans[1] += 1;
    }
    printf("%d", ans[m-1]);
    return 0;
}
